package android.storefront.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.storefront.bussiness.MainActivityDataHandler;
import android.storefront.common.utils.activity.ActivityUtils;
import android.storefront.common.utils.activity.MainMenu;
import android.storefront.valueobject.GridViewVO;
import android.view.KeyEvent;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

public class MainActivity extends Activity{
	
	private GridView main_activity_gridview = null;
	
	private MainMenu mainMenu = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ActivityUtils.getInstance().setPortpaitScreenOrientation(this);
		setContentView(R.layout.main_activity);
		
		main_activity_gridview = (GridView) findViewById(R.id.main_activity_gridview);
		
		int[] wh = ActivityUtils.getInstance().getWidthHight(this);
		main_activity_gridview.setColumnWidth(wh[0]/4);
		
		initGridView(main_activity_gridview);
		
		RelativeLayout menuLayout =  (RelativeLayout) findViewById(R.id.menu_layout);
		mainMenu = MainMenu.getInstance(this, menuLayout);
		ImageButton menu_up_button = (ImageButton) menuLayout.findViewById(R.id.menu_up_button);
		menu_up_button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mainMenu.responseOnKeyDown();
			}
		});
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		mainMenu.responseOnKeyDown(keyCode, event);
		return super.onKeyDown(keyCode, event);
	}
	
	
	
	private void initGridView(GridView main_activity_gridview){
		List<GridViewVO> list = new ArrayList<GridViewVO>();
		list.add(new GridViewVO(R.drawable.a, R.string.main_gridview_a));
		list.add(new GridViewVO(R.drawable.b, R.string.main_gridview_b));
		list.add(new GridViewVO(R.drawable.c, R.string.main_gridview_c));
		list.add(new GridViewVO(R.drawable.d, R.string.main_gridview_d));
		list.add(new GridViewVO(R.drawable.e, R.string.main_gridview_e));
		list.add(new GridViewVO(R.drawable.f, R.string.main_gridview_f));
		list.add(new GridViewVO(R.drawable.g, R.string.main_gridview_g));
		main_activity_gridview.setAdapter(MainActivityDataHandler.getInstance().new GridViewAdapter(this, this, list));
	}
}
